package alan.springboot2x.swagger.knife4j.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @author: Alan
 * @date: 2021/4/29 23:12
 */
@Service("asyncServiceV2")
public class AsyncServiceV2Impl extends IAsyncService {

    @Autowired
    MyTestService myTestService;

    AsyncServiceV2Impl(){
        System.out.println("AsyncServiceV1Impl");
    }

    @Override
    @Async
    public Future<String> getName(String name) {
        try {
            System.out.println("线程名:"+Thread.currentThread().getName());
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new AsyncResult<>("hi:"+name);
    }

    @Override
    @Async
    public Future<Integer> getAge() {
        try {
            System.out.println("线程名:"+Thread.currentThread().getName());
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new AsyncResult<>(22);
    }

}
